﻿using System.Collections.Generic;
using System.Linq;

namespace TodoPro.System.Query
{
    /// <summary>
    /// 获取所有 Todos 的一个查询
    /// </summary>
    public class GetTodosByFilterQuery
    {
        public List<Todo> Do()
        {
            var todoModel = TodoProConfig.GetModel<ITodoModel>();

            if (todoModel.Filter == TodoFilter.All)
            {
                return todoModel.GetAll();
            }

            if (todoModel.Filter == TodoFilter.Active)
            {
                return todoModel.GetAll().Where(todo=>!todo.Finished).ToList();
            }
            
            if (todoModel.Filter == TodoFilter.Completed)
            {
                return todoModel.GetAll().Where(todo=>todo.Finished).ToList();
            }

            return null;
        }
    }
}